﻿using System;
using System.Web.UI.WebControls;
using Bingosoft.Modules.SecurityConsole.Privilege;
using Bingosoft.Web.Utils;

namespace Bingosoft.WebApp.Modules.SecurityConsole.Privilege
{
    public partial class ModuleList : System.Web.UI.BasePage
    {
        private PrivilegeService _privilegeService;
        private PrivilegeService PrivilegeService
        {
            get
            {
                return _privilegeService ??
                       (_privilegeService = ObjectHelper.GetObject<PrivilegeService>("PrivilegeService"));
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void SearchGrid(object sender, EventArgs e)
        {
            this.GridSearch.Search();
        }

        protected void RefreshGrid(object sender, EventArgs e)
        {
            this.GridSearch.Refresh();
        }

        protected void DeleteModule(object sender, EventArgs e)
        {
            ImageButton img = (ImageButton)sender;
            string moduleId = img.Attributes["_KeyId"];

            this.PrivilegeService.DeleteModule(moduleId);

            this.GridSearch.Refresh();
            ScriptHelper.RegisterScript(this, "window.parent.reloadTree();");
        }

        protected void DelModules(object sender, EventArgs e)
        {
            string[] moduleIds = SmartGridView1.GetCheckedValues();

            foreach (string moduleId in moduleIds)
            {
                this.PrivilegeService.DeleteModule(moduleId);
            }

            this.GridSearch.Refresh();
            ScriptHelper.RegisterScript(this, "window.parent.reloadTree();");
        }
    }
}